package 剑指offer.面试题48;

import java.util.HashMap;
import java.util.Map;

public class Solution {
    public int lengthOfLongestSubstring(String s) {
        int max = 0;
        Map<Character,Integer> m = new HashMap<>();
        int left = 0;
        for (int right = 0; right < s.length(); right++) {
            while(m.containsKey(s.charAt(right))){
                m.remove(s.charAt(left));
                left++;
            }
            max = Math.max(max,right-left+1);
            m.put(s.charAt(right),right);
        }
        return max;
    }
}
